package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlModule;
import com.ruoyi.sl.service.ISlModuleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模块Controller
 * 
 * @author admin
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/sl/module")
public class SlModuleController extends BaseController
{
    @Autowired
    private ISlModuleService slModuleService;

    /**
     * 查询模块列表
     */
    @PreAuthorize("@ss.hasPermi('sl:module:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlModule slModule)
    {
        startPage();
        List<SlModule> list = slModuleService.selectSlModuleList(slModule);
        return getDataTable(list);
    }

    /**
     * 获取所有模块
     */
    @GetMapping(value = "/all")
    public AjaxResult getAllModulelist()
    {
        return success(slModuleService.selectModuleAll());
    }

    /**
     * 导出模块列表
     */
    @PreAuthorize("@ss.hasPermi('sl:module:export')")
    @Log(title = "模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlModule slModule)
    {
        List<SlModule> list = slModuleService.selectSlModuleList(slModule);
        ExcelUtil<SlModule> util = new ExcelUtil<SlModule>(SlModule.class);
        util.exportExcel(response, list, "模块数据");
    }

    /**
     * 获取模块详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:module:query')")
    @GetMapping(value = "/{moduleId}")
    public AjaxResult getInfo(@PathVariable("moduleId") Long moduleId)
    {
        return success(slModuleService.selectSlModuleByModuleId(moduleId));
    }

    /**
     * 新增模块
     */
    @PreAuthorize("@ss.hasPermi('sl:module:add')")
    @Log(title = "模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlModule slModule)
    {
        slModule.setCreateBy(getUsername());
        return toAjax(slModuleService.insertSlModule(slModule));
    }

    /**
     * 修改模块
     */
    @PreAuthorize("@ss.hasPermi('sl:module:edit')")
    @Log(title = "模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlModule slModule)
    {
        slModule.setUpdateBy(getUsername());
        return toAjax(slModuleService.updateSlModule(slModule));
    }

    /**
     * 删除模块
     */
    @PreAuthorize("@ss.hasPermi('sl:module:remove')")
    @Log(title = "模块", businessType = BusinessType.DELETE)
	@DeleteMapping("/{moduleIds}")
    public AjaxResult remove(@PathVariable Long[] moduleIds)
    {
        return toAjax(slModuleService.deleteSlModuleByModuleIds(moduleIds));
    }
}
